//
//  CustomTextAlertCloseView.m
//  Elife
//
//  Created by 拓客营 on 2022/4/19.
//

#import "CustomTextAlertCloseView.h"

@interface CustomTextAlertCloseView()

@property (nonatomic, copy) NSString *titleName;
@property (nonatomic, copy) NSString *content;

@end

@implementation CustomTextAlertCloseView

+(void)showTextAlertWithTitle:(NSString *)titleName content:(NSString *)content {
    CustomTextAlertCloseView *view = [[CustomTextAlertCloseView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) titleName:titleName content:content];
    [kWindow addSubview:view];
}

-(instancetype)initWithFrame:(CGRect)frame titleName:(NSString *)titleName content:(NSString *)content{
    if (self = [super initWithFrame:frame]) {
        self.titleName = titleName;
        self.content = content;
        [self UIConfig];
    }
    return self;
}

-(void)UIConfig {
    self.backgroundColor = kRGBA(0x000000, 0.5);
    
    UIView *bgView = [UIView new];
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 10;
    bgView.clipsToBounds = YES;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self);
        make.width.mas_equalTo(ScreenWidth-24);
    }];
    
    UILabel *titlaLab = [UILabel new];
    titlaLab.text = self.titleName;
    titlaLab.textColor = kRGB(0x333333);
    titlaLab.font = [UIFont boldSystemFontOfSize:16];
    [bgView addSubview:titlaLab];
    [titlaLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30);
        make.left.mas_equalTo(25);
        make.height.mas_equalTo(22);
    }];
    
    UILabel *contentLab = [UILabel new];
    contentLab.text = self.content;
    contentLab.textColor = kRGB(0x333333);
    contentLab.font = [UIFont systemFontOfSize:14];
    contentLab.numberOfLines = 0;
    [bgView addSubview:contentLab];
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titlaLab.mas_bottom).offset(20);
        make.left.mas_equalTo(25);
        make.right.mas_equalTo(-25);
        make.bottom.mas_equalTo(-30);
    }];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setImage:ImageWithName(@"icon_alertText_close") forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    closeBtn.expandEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
    [self addSubview:closeBtn];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(bgView.mas_bottom).offset(15);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
}

-(void)closeBtnAction {
    [self removeFromSuperview];
}
@end
